//
//  NSAttributedString+ZXAvoidCrash.m
//  MerchantBusinessClient
//
//  Created by simon on 2020/8/28.
//  Copyright © 2020 com.Chs. All rights reserved.
//

#import "NSAttributedString+ZXAvoidCrash.h"
#import "ZXAvoidCrashRuntime.h"


@implementation NSAttributedString (ZXAvoidCrash)


+ (void)zx_avoidCrashExchangeMethod{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        Class NSConcreteAttributedString = NSClassFromString(@"NSConcreteAttributedString");
        
        //initWithString:
        [ZXAvoidCrashRuntime exchangeInstanceMethodWithClass:NSConcreteAttributedString originalSelector:@selector(initWithString:) swizzledSelector:@selector(zx_avoidCrashInitWithString:)];
    });
}



#pragma mark - initWithString:


- (instancetype)zx_avoidCrashInitWithString:(NSString *)str
{
    id object = nil;
    
    @try {
        object = [self zx_avoidCrashInitWithString:str];
    } @catch (NSException *exception) {
        NSLog(@"%@",exception);
    } @finally {
        return object;
    }
}

@end

// 崩溃：Trapped uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteAttributedString initWithString:: nil value'
